package com.gongpingjialoan.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

import com.gongpingjialoan.utility.DhUtil;

/**
 * Created by Administrator on 2016/1/5.
 */
public class MyCircleView extends View {

    private Paint bigPaint, smallPaint;

    private RectF mRectF;

    private int startAngle;

    private int Strokewidth;

    public MyCircleView(Context context) {
        this(context, null);
    }

    public MyCircleView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public MyCircleView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        int width = Math.min(getMeasuredWidth(), getMeasuredHeight());
        mRectF = new RectF(getPaddingLeft() + Strokewidth, getPaddingTop() + Strokewidth, width - getPaddingRight() - getPaddingLeft() - Strokewidth, width - Strokewidth - getPaddingBottom() - getPaddingTop());
        setMeasuredDimension(width, width);
    }

    private void init() {
        Strokewidth  = DhUtil.dip2px(getContext() , 7);
        bigPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        smallPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        bigPaint.setStyle(Paint.Style.STROKE);
        bigPaint.setColor(Color.parseColor("#e6e6e6"));
        bigPaint.setStrokeWidth(Strokewidth);
        smallPaint.setColor(Color.parseColor("#18A0E0"));
        smallPaint.setStrokeWidth(Strokewidth);
        smallPaint.setStyle(Paint.Style.STROKE);
        smallPaint.setStrokeCap(Paint.Cap.ROUND);
    }


    @Override
    protected void onDraw(Canvas canvas) {
        canvas.drawArc(mRectF, 0f, 360f, false, bigPaint);
        canvas.drawArc(mRectF, startAngle, 45, false, smallPaint);
        startAngle += 5;
        invalidate();
    }



}

